package operate;
import book.Book;
import book.BookList;
import user.User;

import java.util.Iterator;
import java.util.Scanner;
public class Del implements IOperate{
    /**
     * 负责人：汤姆猫
     * 功能：删除书籍
     * 让用户输入要删除的书籍
     * 如果bookList集合里有书，则删除
     * 没有则打印：XXXXXXXXXX
     * 把书从bookList集合里删除
     * 参数：无
     * 返回类型：void
     */
    @Override
    public void operate(User user, BookList bookList) {
        if (bookList.bookLists.size() == 0) {
            System.out.println("书目为空,无法进行下架操作");
            return;
        }
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要下架的书籍名称:");
        String input = sc.nextLine();
        boolean removed = false;//标记
        Iterator<Book> iterator = bookList.bookLists.iterator();
        while (iterator.hasNext()) {
            Book book = iterator.next();
            if (book.getName().equals(input)) {
                iterator.remove();
                removed = true;
                System.out.println("书籍下架成功");
                break;
            }
        }
        if (!removed) {
            System.out.println("未找到匹配的书籍");
        }
    }
}
